const md5 = require("md5");
const Users = require("../data/Users");
module.exports = {
  //根据用户名和密码查询用户信息
  async Login(userName, password) {
    password = md5(password);
    const result = await Users.findOne({
      where: {
        userName,
        password,
      },
    });
    if (result) {
      return result.toJSON();
    }
    return null;
  },

  //根据用户名查询用户信息
  async FindUserName(userName) {
    const result = await Users.findOne({
        where:{
            userName
        }
    });
    if(result){
        return result.toJSON();
    }
    return null;
  },

  //插入用户信息
  async Register(userName,password){
    password = md5(password);
    const ins = await Users.create({
        userName,
        password
    });
    return ins.toJSON();
  }
};
